<?php

namespace App\Http\Controllers\Api\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Facades\Services\Admin\DoctorService;
use App\Facades\Utils\ValidateParameter;
use App\Models\WeChatDoctorInfo;

class DoctorController extends Controller
{
    public function createDoctorInfo(Request $request){

        $rules = [
            'name' => 'required',
            'job_title' => 'required',
            'dr_type' => 'required|in:'.implode(',',array_keys(WeChatDoctorInfo::$DRTYPE)),
            'resume' => 'required',
            'headimg' => 'required',
            'hospital' => 'required',
            'section' => 'required',
            'wechat_doctor_id' => 'required|exists:wechat_doctors,id'
        ];

        ValidateParameter::validate($request,$rules);

        $data = $request->all();

        DoctorService::createDoctorInfo($data);

        return formatJsonResponse();
    }

    public function updateDoctorInfo(Request $request){

        $rules = [
            'id' => "required|exists:wechat_doctor_infos,id",
            'name' => 'required',
            'job_title' => 'required',
            'dr_type' => 'required|in:'.implode(',',array_keys(WeChatDoctorInfo::$DRTYPE)),
            'resume' => 'required',
            'hospital' => 'required',
            'section' => 'required'
        ];

        ValidateParameter::validate($request,$rules);

        $data = $request->all();

        DoctorService::updateDoctorInfo($data);

        return formatJsonResponse();
    }
}
